localStorage.urlId = Util.GetQueryString('userId')
Cardlist.getUserInfo({
	userId: localStorage.urlId
},function(res){
	$('.firstBox').focus(); //初始化页面第一个为触发状态
	var paywdBox;
	$('.paywdBox > input').keyup(function(event){
		$('#iconBox').css('display','none');
		var inputVal = '';
		paywdBox = 	$('.paywdBox > input');
		for(var i = 0; i<paywdBox.length; i++){
			if($(paywdBox[i]).val() != ''){
				inputVal = inputVal + $(paywdBox[i]).val();
			}
		}
		if($(this).val().length >= 1){
			if(!$(this).hasClass('lastBox') && inputVal.length != 6 && $(this).val().length == 1){
				$(this).next().focus();
			}else if($(this).val().length >1){
				$(this).val('');
			}
		}else if($(this).val().length == 0){
			if(!$(this).hasClass('firstBox')){
				$(this).prev().focus();	
			}
		}
		
		//判断字符串长度 若长度为6 则提交
		if(inputVal.length == 6){
			Pay.checkPayPwd({
				userId: localStorage.urlId,
				payPwd: $.base64.encode(inputVal)
			},function(res){
			    localStorage.rpUserId = Util.GetQueryString('userId'); //验证成功后缓存用户Id
				location.hash = 'cardlist';
			})
		}
	});
	
	//确认修改提现密码
	$('.confirm').click(function(){
		var reg = new RegExp("^[0-9]*$");
		var oldPayPwd = $('#oldPayPwd').val();
		var newPayPwd = $('#newPayPwd').val();
		var PayCode = $('#verifyCode').val();
		if(PayCode != ''){
			if(oldPayPwd == newPayPwd && newPayPwd.length == 6 && reg.test(oldPayPwd)){
				Pay.modifyPayPwd({
					userId: localStorage.urlId, //userId
					payPwd: ' ', //原支付密码
					newPayPwd: $.base64.encode(newPayPwd), //新密码
					phone: localStorage.phone, //用户手机号
					verifyCode: PayCode,
					bizType: 2
				},function(res){
					layer.open({content: '添加支付密码成功！' ,skin: 'msg',time: 2});
					setTimeout(function() {$('#paymodel').hide();},2000);
				})
			}else{
				layer.open({content: '密码不合法' ,skin: 'msg',time: 2});
			}
		}else{
			layer.open({content: '验证码不能为空' ,skin: 'msg',time: 2});
		}

	});
	
	
	//获取修改密码验证码
	$('.getems').click(function(){
		VerifyCode.checkVerifyCode({
			phone: localStorage.phone, //用户手机号
			bizType: 4 //验证码类型
		},function(res){})
	});
});
